<template>
  <div class="message-detail-page">
    <div class="message-content">
      <div v-if="loading" class="loading-container">
        <van-loading type="spinner" color="#d4a353" size="24px" />
      </div>
      
      <div v-else-if="!message" class="no-message">
        <NoData text="Pesan tidak ditemukan" />
      </div>
      
      <div v-else class="message-detail">
        <div class="message-header">
          <div class="notification-icon">
            <img src="@/assets/images/user/iconInfo.png" alt="notification" />
          </div>
          <div class="message-id">ID: {{ messageId }}</div>
        </div>
        
        <div class="message-body">
          <div class="message-text">{{ message.content }}</div>
          
          <div class="message-info">
            <!-- <div class="info-item">
              <div class="label">Status</div>
              <div class="value" :class="message.status">
                {{ message.status === 'success' ? 'Berhasil' : 'Gagal' }}
              </div>
            </div> -->
            
            <div class="info-item">
              <div class="label">Tanggal</div>
              <div class="value">{{ message.date }}</div>
            </div>
            
            <div class="info-item">
              <div class="label">Waktu</div>
              <div class="value">{{ message.time }}</div>
            </div>
          </div>
        </div>
        
        <!-- <div class="message-footer">
          <div class="time-full">{{ message.date }} {{ message.time }}</div>
          <div v-if="message.tip" class="message-tip">{{ message.tip }}</div>
        </div> -->
      </div>
    </div>
  </div>
</template>

<script setup>
import NoData from '@/components/NoData.vue'
import { showToast, Loading as VanLoading } from 'vant/es'
import { onMounted, ref } from 'vue'
import { useRoute, useRouter } from 'vue-router'

const router = useRouter()
const route = useRoute()
const messageId = ref(route.query.id || '')
const message = ref(null)
const loading = ref(true)

onMounted(() => {
  if (!messageId.value) {
    showToast('ID pesan tidak valid')
    loading.value = false
    return
  }
  
  // 模拟API调用获取消息详情
  fetchMessageDetail()
})

function fetchMessageDetail() {
  // 模拟API延迟
  setTimeout(() => {
    // 模拟根据ID查询消息
    if (messageId.value === '2667909174546495') {
      message.value = {
        id: '2667909174546495',
        content: 'Penarikan Anda [2667909174546495] telah berhasil diproses. Dana telah tiba pada 12:53 24/04/2025. Silakan periksa.',
        status: 'success',
        date: '24/04/2025',
        time: '12:53',
        tip: 'Terima kasih telah menggunakan layanan kami.'
      }
    } else if (messageId.value === '2667909174546769') {
      message.value = {
        id: '2667909174546769',
        content: 'Maaf, penarikan Anda [2667909174546769] gagal. Alasannya: informasi akun mungkin salah. Silakan periksa detail akun bank Anda dan coba lagi nanti.',
        status: 'error',
        date: '24/04/2025',
        time: '11:19',
        tip: 'Jika Anda memerlukan bantuan, silakan hubungi tim dukungan kami.'
      }
    } else if (messageId.value === 'T1431') {
      message.value = {
        id: 'T1431',
        content: 'Anda telah berhasil berlangganan produk investasi[T1431]. Terima kasih atas kepercayaan dan dukungan Anda.',
        status: 'success',
        date: '19/04/2025',
        time: '14:19',
        tip: 'Lihat portofolio Anda untuk memantau perkembangan investasi.'
      }
    }
    
    loading.value = false
  }, 800)
}
</script>

<style lang="less" scoped>
.message-detail-page {
  min-height: 100vh;
  background-color: #1c1815;
  padding-bottom: 30px;
}

.page-header {
  display: flex;
  align-items: center;
  padding: 15px;
  position: relative;
  background-image: url('@/assets/images/user/Topbg.png');
  background-size: cover;
  background-position: top center;
  
  .back-button {
    position: absolute;
    left: 15px;
    width: 20px;
    height: 20px;
    cursor: pointer;
    
    img {
      width: 100%;
      height: 100%;
    }
  }
  
  .page-title {
    flex: 1;
    text-align: center;
    font-size: 16px;
    font-weight: 500;
    color: #f6e0ca;
  }
}

.message-content {
  padding: 15px;
}

.loading-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 200px;
}

.no-message {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 300px;
}

.message-detail {
  background-color: #2a2421;
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.message-header {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
  
  .notification-icon {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background-color: #443f3c;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 15px;
    
    img {
      width: 20px;
      height: 20px;
      opacity: 0.8;
    }
  }
  
  .message-id {
    font-size: 14px;
    color: #999;
    font-weight: 300;
  }
}

.message-body {
  margin-bottom: 20px;
  
  .message-text {
    font-size: 15px;
    line-height: 1.6;
    color: #f6e0ca;
    margin-bottom: 25px;
    font-weight: 300;
  }
}

.message-info {
  background-color: #252220;
  border-radius: 8px;
  padding: 15px;
  
  .info-item {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid #333;
    
    &:last-child {
      margin-bottom: 0;
      padding-bottom: 0;
      border-bottom: none;
    }
    
    .label {
      font-size: 14px;
      color: #999;
    }
    
    .value {
      font-size: 14px;
      color: #f6e0ca;
      font-weight: 500;
      
      &.success {
        color: #4cd964;
      }
      
      &.error {
        color: #ff3b30;
      }
    }
  }
}

.message-footer {
  margin-top: 20px;
  padding-top: 15px;
  border-top: 1px dashed #333;
  
  .time-full {
    font-size: 12px;
    color: #777;
    text-align: right;
    margin-bottom: 10px;
  }
  
  .message-tip {
    font-size: 14px;
    color: #d4a353;
    font-style: italic;
    text-align: center;
    padding: 10px;
    background-color: rgba(212, 163, 83, 0.1);
    border-radius: 4px;
  }
}
</style> 